/**
 * @param {string} n
 * @param {number} x
 * @return {string}
 */
 var maxValue = function(n, x) {
    let flag = n.includes('-')
    let arr = n.split('')
    if(!flag){
        let i = 0
        while(Number(arr[i]) >= x) i++
        arr.splice(i, 0, x)
    }else{
        let j = 1
        while(Number(arr[j]) <= x) j++
        arr.splice(j, 0, x)
    }
    return arr.join('')
};